from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep
from appium.webdriver.common.touch_action import TouchAction

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['app'] = r'D:\RJCS\Appium/mymoney.apk'
desired_caps['appPackage'] = r'com.mymoney'
desired_caps['appActivity'] = r'com.mymoney.biz.splash.SplashScreenActivity'
desired_caps['noReset'] = True  # False代表重置（重新安装），默认值就是False

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)  # 隐式等待
sleep(3)

# 点击 同意
try:
    ele = driver.find_element(By.ID, 'com.mymoney:id/sui_dialog_positive_btn_style1')
except Exception as e:
    print('no cancelBtn')
else:
    ele.click()

# 点击 账本
try:
    ele = driver.find_element(By.ID, 'com.mymoney:id/select_template_btn')
except Exception as e:
    print('no skipBtn')
else:
    ele.click()

# 点击 登录
try:
    ele = driver.find_element(By.ID, 'com.mymoney:id/bottom_skip_tv')
except Exception as e:
    print('no skipBtn')
else:
    ele.click()

driver.find_element(By.ID, 'com.mymoney:id/account_centre_icon_default_iv').click() # 我的
driver.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[9]/android.widget.LinearLayout').click()


# for i in range(2):
#     TouchAction(driver).press(x=150, y=320).wait(1000).move_to(x=500, y=320).wait(1000).move_to(x=500, y=520).wait(
#         1000).release().perform()

driver.quit()